#!/bin/sh
#
# Construct pmlogrewrite rules ...
# proc_kernel_ulong.conf
#	Needs to be done dynamically because the type of KERNEL_ULONG is
#	platform dependent.
# proc_jiffies.conf
#	Various time metrics that are counted in jiffies and scaled up
#	to msec, requiring the type to be PM_TYPE_U64
#

tmp=/var/tmp/$$
trap "rm -f $tmp.*; exit 0" 0 1 2 3 15

cat <<End-of-File >$tmp.c
#include <pcp/platform_defs.h>
#if defined(HAVE_64BIT_LONG)
KERNEL_ULONG=PM_TYPE_U64
#elif defined(HAVE_32BIT_LONG)
KERNEL_ULONG=PM_TYPE_U32
#else
# bozo!
#endif
End-of-File

eval `${CPP-cpp} -I${INCDIR-.} $tmp.c \
      | sed -n -e '/KERNEL_ULONG/s/PM_TYPE_//p'`

cat <<End-of-File >proc_kernel_ulong.conf
# These metrics are all exported from the proc PMDA
# using the KERNEL_ULONG type which might be PM_TYPE_U32
# or could be PM_TYPE_U64. 

metric proc.psinfo.wchan { type -> $KERNEL_ULONG }
metric proc.schedstat.pcount { type -> $KERNEL_ULONG }
End-of-File

cat <<End-of-File >proc_kernel_ulong_migrate.conf
# These metrics are exported by the kernel as unsigned long long on
# both 32bit and 64bit systems. So they all migrate from U32 to U64.
# See kernel function seq_put_decimal_ull() in fs/seq_file.c and it's
# use in fs/proc/array.c. There are others too, but these are the
# most important, especially proc.psinfo.vsize.

metric proc.psinfo.vsize { type -> U64 }
metric proc.psinfo.rss { type -> U64 }
metric proc.psinfo.rss_lim { type -> U64 }
End-of-File

cat <<End-of-File >proc_jiffies.conf
# These metrics are counted in jiffies but exported from the proc
# PMDA as milliseconds of type PM_TYPE_U64 or KERNEL_ULONG

metric proc.psinfo.utime { type -> $KERNEL_ULONG }
metric proc.psinfo.stime { type -> $KERNEL_ULONG }
metric proc.psinfo.cutime { type -> $KERNEL_ULONG }
metric proc.psinfo.cstime { type -> $KERNEL_ULONG }
metric proc.psinfo.delayacct_blkio_time { type -> U64 units -> 0,1,0,0,MSEC,0 }
metric proc.psinfo.guest_time { type -> U64 units -> 0,1,0,0,MSEC,0 }
metric proc.psinfo.cguest_time { type -> U64 units -> 0,1,0,0,MSEC,0 }
metric proc.psinfo.start_time { type -> U64 units -> 0,1,0,0,MSEC,0 }
metric cgroup.blkio.dev.time { type -> U64 }
metric cgroup.blkio.all.time { type -> U64 }
End-of-File

exit 0
